#include <string.h>
#include <stdio.h>

/*
 * 传递参数机制		P191
 */

struct zzz
{
	char s[16];
	int x;
};

void func(double a, struct zzz y)
{
	printf("%f %x %s.\n", a, y.x, &y.s[0]);
}

int main()
{
	struct zzz y;
	
	strcpy(&y.s[0], "Hello, xiaozhi!");
	y.x = 0x666;
	
	func(6.66, y);
}



#if 0

/*
 * intel
 */

1.将字符串拆解为整型常量，然后赋值到栈空间上

0000000000001169 <func>:
    1169:	f3 0f 1e fa          	endbr64 
    116d:	55                   	push   %rbp
    116e:	48 89 e5             	mov    %rsp,%rbp	// rbp=rsp
    1171:	48 83 ec 10          	sub    $0x10,%rsp	// rsp-=0x10
    1175:	f2 0f 11 45 f8       	movsd  %xmm0,-0x8(%rbp)	// rbp-0x8=xmm0	传送双字串
    117a:	8b 4d 20             	mov    0x20(%rbp),%ecx	// ecx=rbp-0x20
    117d:	48 8b 45 f8          	mov    -0x8(%rbp),%rax	// rax=rbp-0x8
    1181:	48 8d 55 10          	lea    0x10(%rbp),%rdx	// rdx=rbp-0x10
    1185:	89 ce                	mov    %ecx,%esi	// esi=ecx
    1187:	66 48 0f 6e c0       	movq   %rax,%xmm0	// xmm0=rax
    118c:	48 8d 3d 75 0e 00 00 	lea    0xe75(%rip),%rdi        # 2008 <_IO_stdin_used+0x8> rdi=rip+0xe75
    1193:	b8 01 00 00 00       	mov    $0x1,%eax	// eax=1
    1198:	e8 d3 fe ff ff       	callq  1070 <printf@plt>	// printf(rdi, rax, 
    119d:	90                   	nop
    119e:	c9                   	leaveq 
    119f:	c3                   	retq   

00000000000011a0 <main>:
    11a0:	f3 0f 1e fa          	endbr64 
    11a4:	55                   	push   %rbp
    11a5:	48 89 e5             	mov    %rsp,%rbp		// rbp=rsp
    11a8:	48 83 ec 20          	sub    $0x20,%rsp		// rsp=rsp-0x20
    11ac:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax		// rax=fs:0x28
    11b3:	00 00 
    11b5:	48 89 45 f8          	mov    %rax,-0x8(%rbp)		// rbp-0x8=rax
    11b9:	31 c0                	xor    %eax,%eax		// eax=0
    11bb:	48 8d 45 e0          	lea    -0x20(%rbp),%rax		// rax=rbp-0x20
    11bf:	48 ba 48 65 6c 6c 6f 	movabs $0x78202c6f6c6c6548,%rdx	// rdx=0x78202c6f6c6c6548="x ,olleH"
    11c6:	2c 20 78 
    11c9:	48 b9 69 61 6f 7a 68 	movabs $0x2169687a6f6169,%rcx	// rcx=$0x2169687a6f6169"!ihzoai"
    11d0:	69 21 00 
    11d3:	48 89 10             	mov    %rdx,(%rax)		// (rax)=(rbp-0x20)=0x78202c6f6c6c6548
    11d6:	48 89 48 08          	mov    %rcx,0x8(%rax)		// (rax)+8=(rbp-0x20+0x8)=(rbp-0x18)=0x2169687a6f6169
    11da:	c7 45 f0 66 06 00 00 	movl   $0x666,-0x10(%rbp)	// rbp-0x10=0x666   ---> y.x=0x666
    11e1:	48 8b 35 30 0e 00 00 	mov    0xe30(%rip),%rsi        # 2018 <_IO_stdin_used+0x18> rsi=rip+0xe30=6.6
    11e8:	48 83 ec 08          	sub    $0x8,%rsp		// rsp=rsp-0x20-0x8	 = rsp-0x28
    11ec:	48 83 ec 18          	sub    $0x18,%rsp		// rsp=rsp-0x20-0x8-0x18 = rsp-0x40      
    11f0:	48 89 e1             	mov    %rsp,%rcx		// rcx=rsp-0x40
    11f3:	48 8b 45 e0          	mov    -0x20(%rbp),%rax		// rax=rbp-0x20 = 0x78202c6f6c6c6548
    11f7:	48 8b 55 e8          	mov    -0x18(%rbp),%rdx		// rdx=rbp-0x18 = 0x002169687a6f6169
    11fb:	48 89 01             	mov    %rax,(%rcx)		// (rcx)=(rsp-0x40)=0x78202c6f6c6c6548
    11fe:	48 89 51 08          	mov    %rdx,0x8(%rcx)		// rcx+8=(rsp-0x40+0x8)=(rsp-0x38)=0x002169687a6f6169
    1202:	8b 45 f0             	mov    -0x10(%rbp),%eax		// eax=rbp-0x10=0x666
    1205:	89 41 10             	mov    %eax,0x10(%rcx)		// rcx+0x10=(rsp-0x40+0x10)=(rsp-0x30)=eax=0x666
    1208:	66 48 0f 6e c6       	movq   %rsi,%xmm0		// xmm0=rsi=6.6
    120d:	e8 57 ff ff ff       	callq  1169 <func>		// func(xmm0, 
    1212:	48 83 c4 20          	add    $0x20,%rsp
    1216:	b8 00 00 00 00       	mov    $0x0,%eax
    121b:	48 8b 7d f8          	mov    -0x8(%rbp),%rdi
    121f:	64 48 33 3c 25 28 00 	xor    %fs:0x28,%rdi
    1226:	00 00 
    1228:	74 05                	je     122f <main+0x8f>
    122a:	e8 31 fe ff ff       	callq  1060 <__stack_chk_fail@plt>
    122f:	c9                   	leaveq 
    1230:	c3                   	retq   
    1231:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
    1238:	00 00 00 
    123b:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)

/*
 * arm
 */
000000000040055c <func>:
  40055c:	a9bd7bfd 	stp	x29, x30, [sp, #-48]!
  400560:	910003fd 	mov	x29, sp
  400564:	f9000bf3 	str	x19, [sp, #16]
  400568:	fd0017a0 	str	d0, [x29, #40]
  40056c:	aa0003f3 	mov	x19, x0
  400570:	b9401261 	ldr	w1, [x19, #16]
  400574:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  400578:	911aa000 	add	x0, x0, #0x6a8
  40057c:	aa1303e2 	mov	x2, x19
  400580:	fd4017a0 	ldr	d0, [x29, #40]
  400584:	97ffffb3 	bl	400450 <printf@plt>
  400588:	d503201f 	nop
  40058c:	f9400bf3 	ldr	x19, [sp, #16]
  400590:	a8c37bfd 	ldp	x29, x30, [sp], #48
  400594:	d65f03c0 	ret

0000000000400598 <main>:
  400598:	a9bb7bfd 	stp	x29, x30, [sp, #-80]!
  40059c:	910003fd 	mov	x29, sp
  4005a0:	9100e3a2 	add	x2, x29, #0x38
  4005a4:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  4005a8:	911ae000 	add	x0, x0, #0x6b8
  4005ac:	a9400400 	ldp	x0, x1, [x0]
  4005b0:	a9000440 	stp	x0, x1, [x2]
  4005b4:	5280ccc0 	mov	w0, #0x666                 	// #1638
  4005b8:	b9004ba0 	str	w0, [x29, #72]
  4005bc:	910043a2 	add	x2, x29, #0x10
  4005c0:	9100e3a3 	add	x3, x29, #0x38
  4005c4:	a9400460 	ldp	x0, x1, [x3]
  4005c8:	a9000440 	stp	x0, x1, [x2]
  4005cc:	b9401060 	ldr	w0, [x3, #16]
  4005d0:	b9001040 	str	w0, [x2, #16]
  4005d4:	910043a1 	add	x1, x29, #0x10
  4005d8:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  4005dc:	911b2000 	add	x0, x0, #0x6c8
  4005e0:	fd400000 	ldr	d0, [x0]
  4005e4:	aa0103e0 	mov	x0, x1
  4005e8:	97ffffdd 	bl	40055c <func>
  4005ec:	52800000 	mov	w0, #0x0                   	// #0
  4005f0:	a8c57bfd 	ldp	x29, x30, [sp], #80
  4005f4:	d65f03c0 	ret

 #endif
